package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.common.validator.ValidatorUtils;
import edu.nf.relaxenjoy.common.validator.group.DefaultGroup;
import edu.nf.relaxenjoy.domain.dto.AlbumDTO;
import edu.nf.relaxenjoy.domain.vo.AlbumVo;
import edu.nf.relaxenjoy.service.AlbumService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/album")
@Api(tags="专辑模块")
public class AlbumController extends BaseController {

    private final AlbumService albumService;

    /**
     * 得到当前用户的所有专辑
     *
     * @param uid
     * @return
     */
    @RequestMapping("getAllAlbum")
    public ResultVO getAllAlbum(@RequestParam("uid") Long uid) {
        List<AlbumVo> voList = albumService.getAllAlbum(uid);
        return success(voList);
    }

    /**
     * 保存专辑
     *
     * @param albumDTO
     * @return
     */
    @RequestMapping("saveAlbum")
    public ResultVO saveAlbum(@RequestBody AlbumDTO albumDTO) {
        ValidatorUtils.validateEntity(albumDTO, DefaultGroup.class);
        albumService.saveAlbum(albumDTO);
        return success();
    }

    /**
     * 得到专辑信息
     *
     * @param id
     * @return
     */
    @RequestMapping("getAlbum")
    public ResultVO getAlbum(@RequestParam("id") String id) {
        AlbumVo albumVo = albumService.getAlbum(id);
        return success(albumVo);
    }


    /**
     * 删除专辑
     *
     * @param id
     * @param uid
     * @return
     */
    @RequestMapping("deleteAlbum")
    public ResultVO deleteAlbum(String id, String uid) {
        albumService.deleteAlbum(id, uid);
        return success();
    }


    /**
     * 更新专辑
     *
     * @param albumDTO
     * @return
     */
    @RequestMapping("updateAlbum")
    public ResultVO updateAlbum(@RequestBody AlbumDTO albumDTO) {
        ValidatorUtils.validateEntity(albumDTO, DefaultGroup.class);
        albumService.updateAlbum(albumDTO);
        return success();
    }
}
